package anbow.ch3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * 2,3,5,0,7,8,0 
 * 2,3,5,0,7,8,0
 * @author Administrator
 *
 */

public class IsSameTree {

	public static void main(String[] args) throws IOException {
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String line2 = br.readLine();
		
		String[] arr1 = line1.split(",");
		String[] arr2 = line2.split(",");
		
		int[] nums1 = new int[arr1.length];
		int[] nums2 = new int[arr2.length];
		
		for(int i=0;i<arr1.length;i++) {
			nums1[i] = Integer.valueOf(arr1[i]);
		}
		
		for(int i=0;i<arr2.length;i++) {
			nums2[i] = Integer.valueOf(arr2[i]);
		}
		
		//int[] nums1 = {2,3,5,0,7,8,0};
		//int[] nums2 = {2,3,5,0,7,8,0};
		
		TreeNode t1 = initTree(nums1);
		TreeNode t2 = initTree(nums2);
		
		boolean yn = same(t1,t2);
		System.out.println(yn);
	}
	
	private static boolean same(TreeNode t1, TreeNode t2) {
		if(t1==null && t2==null) {
			return true;
		}else if(t1==null || t2==null) {
			return false;
		}
		
		if(t1.val != t2.val) {
			return false;
		}
		
		boolean left = same(t1.left,t2.left);
		boolean right = same(t1.right,t2.right);
		
		return left && right;
	}

	private static TreeNode initTree(int[] nums) {
		TreeNode[] nodes = new TreeNode[nums.length];
		for(int i=0;i<nodes.length;i++) {
			if(nums[i] == 0) {
				nodes[i] = null;
			}else {
				nodes[i] = new TreeNode(nums[i]);
			}			
		}
		for(int i=0;i<nodes.length;i++) {
			int leftIndex = 2*i+1;
			int rightIndex = 2*i+2;
			if(nodes[i] != null && leftIndex<nodes.length) {
				nodes[i].left = nodes[leftIndex];
			}
			if(nodes[i] != null && rightIndex<nodes.length) {
				nodes[i].right = nodes[rightIndex];
			}
		}
		return nodes[0];
	}

}


class TreeNode {

	int val;
	TreeNode left;
	TreeNode right;
	
	public TreeNode() {
		super();
	}

	public TreeNode(int val) {
		super();
		this.val = val;
	}

	public TreeNode(TreeNode left, TreeNode right) {
		super();
		this.left = left;
		this.right = right;
	}

	public TreeNode(int val, TreeNode left, TreeNode right) {
		super();
		this.val = val;
		this.left = left;
		this.right = right;
	}
}

